#include "Triangles.h"

Triangles::Triangles(Vector3f * points)
{
	mPoints = points;
}

Triangles::~Triangles(void)
{
}

int Triangles::returnType()
{
	return AShape::TYPE_TRIANGLE;
}
void Triangles::drawGL()
{
	glColor3f((*mColor)[0],(*mColor)[1],(*mColor)[2]);
	glBegin(GL_TRIANGLES);
	glVertex3d(mPoints[0][0],mPoints[0][1],mPoints[0][2]);
	glVertex3d(mPoints[1][0],mPoints[1][1],mPoints[1][2]);
	glVertex3d(mPoints[2][0],mPoints[2][1],mPoints[2][2]);
	glEnd();

	glBegin(GL_POINTS);
	glVertex3d(mPoints[0][0],mPoints[0][1],mPoints[0][2]);
	glVertex3d(mPoints[1][0],mPoints[1][1],mPoints[1][2]);
	glVertex3d(mPoints[2][0],mPoints[2][1],mPoints[2][2]);
	glEnd();
}

Vector3f* Triangles::clickOnMarker(Vector2f* mousePos, int indexX, int indexY, int markerRadius)
{
	float mouseX = (*mousePos)[0];
	float mouseY = (*mousePos)[1];

	for (int j = 0; j < 3; j++)
	{
		if (mouseX > (mPoints[j][indexX]-markerRadius) && mouseX < (mPoints[j][indexX]+markerRadius))
		{
			if (mouseY > (mPoints[j][indexY]-markerRadius) && mouseY < (mPoints[j][indexY]+markerRadius))
			{
				return &mPoints[j];
			}
		}
	}
	return NULL;
}

float Triangles::perimeterLength()
{
	float len = 0;
	len += std::sqrt(std::pow(mPoints[1][0] - mPoints[0][0], 2) + std::pow(mPoints[1][1] - mPoints[0][1], 2)+ std::pow(mPoints[1][2] - mPoints[0][2], 2));
	len += std::sqrt(std::pow(mPoints[2][0] - mPoints[1][0], 2) + std::pow(mPoints[2][1] - mPoints[1][1], 2)+ std::pow(mPoints[2][2] - mPoints[1][2], 2));
	len += std::sqrt(std::pow(mPoints[0][0] - mPoints[2][0], 2) + std::pow(mPoints[0][1] - mPoints[2][1], 2)+ std::pow(mPoints[0][2] - mPoints[2][2], 2));
	return len;
}
